package org.zebra.redisson.codec;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.msgpack.jackson.dataformat.MessagePackFactory;
import org.redisson.codec.JsonJacksonCodec;
import org.zebra.cache.serializer.GenericMsgPackRedisSerializer;
import org.zebra.common.util.ReflectPlusUtil;

/**
 * msgpack 适配
 *
 * @author zhanghongbin
 */
public class MsgPackPlusJacksonCodec extends JsonJacksonCodec {

    public MsgPackPlusJacksonCodec() {
        super((ObjectMapper) ReflectPlusUtil.getFieldValue(GenericMsgPackRedisSerializer.getInstance(), "mapper"));
    }

    public MsgPackPlusJacksonCodec(ClassLoader classLoader) {
        super(createObjectMapper(classLoader, new ObjectMapper(new MessagePackFactory())));
    }

    public MsgPackPlusJacksonCodec(ClassLoader classLoader, MsgPackPlusJacksonCodec codec) {
        super(createObjectMapper(classLoader, codec.mapObjectMapper.copy()));
    }
}
